#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pii pair<int,int>
#define pli pair<ll,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define pb push_back
int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

template <typename T>
void write(T x){
	bool sgn = 0;
	if(x < 0) x = -x,sgn = 1;
	T stk[20],cnt = 0;
	while(x){
		stk[++cnt] = x%10;
		x/=10;
	}
	if(sgn) putchar('-');
	for(int i = cnt;i >= 1;i--) putchar(stk[i]+48);
	if(cnt == 0) putchar('0');
	putchar(' ');
}

const int MAXN = 1e5+10;
const ll inf = 0x3f3f3f3f3f3f3f3f;

typedef struct {int v,w;}edge;

ll dis[MAXN*9],ans;
int n,q,s,out[MAXN<<2],to[MAXN<<2],tot;
vector<edge>G[MAXN*9];
bool vis[MAXN*9];

void build(int o = 1,int l = 1,int r = n){
	if(l == r) {out[o] = l; to[o] = l;return;}
	out[o] = ++tot;to[o] = ++tot;
	int mid = l+r>>1;
	build(o<<1,l,mid);build(o<<1|1,mid+1,r);
	G[to[o]].pb(edge{to[o<<1],0});G[to[o]].pb(edge{to[o<<1|1],0});
	G[out[o<<1]].pb(edge{out[o],0});G[out[o<<1|1]].pb(edge{out[o],0});
}

void upd(int xl,int xr,int u,int w,int type,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r){
		if(!type) G[u].pb(edge{to[o],w});
		else G[out[o]].pb(edge{u,w});
		return;
	}
	int mid = l+r>>1;
	if(xr <= mid) upd(xl,xr,u,w,type,o<<1,l,mid);
	else if(xl > mid) upd(xl,xr,u,w,type,o<<1|1,mid+1,r);
	else upd(xl,mid,u,w,type,o<<1,l,mid),upd(mid+1,xr,u,w,type,o<<1|1,mid+1,r);
}

void dijk(){
	memset(dis,0x3f,sizeof(dis));
	dis[s] = 0;
	priority_queue<pli>q;
	q.push(pli(0,s));
	while(q.size()){
		int x = q.top().se;q.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(int i = 0;i < G[x].size();i++){
			int y = G[x][i].v;
			if(dis[y] > dis[x] + G[x][i].w){
				dis[y] = dis[x] + G[x][i].w;
				q.push(pli(-dis[y],y));
			}
		}
	}
}
int main (){
	n = in,q = in,s = in;
	tot = n;
	build();
	while(q--){
		int op = in;
		if(op == 1) {
			int u = in,v = in,w = in;
			G[u].pb(edge{v,w});
		}else if(op == 2){
			int u = in,l = in,r = in,w = in;
			upd(l,r,u,w,0);
		}else{
			int u = in,l = in,r = in,w = in;
			upd(l,r,u,w,1);
		}
	}
	dijk();
	for(int i = 1;i <= n;i++){
		ans = dis[i];
		if(ans == inf) ans = -1;
		write(ans);
	}
	return 0;
}
